package com.OrderingSystem.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.*;
import org.springframework.web.filter.CorsFilter;

/**
 * 跨域配置类,解决跨域问题
 * 允许所有域名跨域
 * 允许所有请求方法跨域
 * 允许所有请求头跨域
 * 允许凭证跨域
 */
@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");//允许所有域名跨域
        config.addAllowedHeader("*");//允许所有请求头跨域
        config.addAllowedMethod("*");//允许所有请求方法跨域
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
}
